package com.luckyframe.project.jmeter.jmeterMetric.controller;

import com.luckyframe.common.utils.poi.ExcelUtil;
import com.luckyframe.framework.aspectj.lang.annotation.Log;
import com.luckyframe.framework.aspectj.lang.enums.BusinessType;
import com.luckyframe.framework.web.controller.BaseController;
import com.luckyframe.framework.web.domain.AjaxResult;
import com.luckyframe.framework.web.page.TableDataInfo;
import com.luckyframe.project.jmeter.jmeterMetric.domain.JmeterMetric;
import com.luckyframe.project.jmeter.jmeterMetric.service.IJmeterMetricService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * jmeter测试计划调度 信息操作处理
 * 
 * @author lancelot
 * @date 2020-11-02
 */
@Controller
@RequestMapping("/jmeter/jmeterMetric")
public class JmeterMetricController extends BaseController
{
    private String prefix = "jmeter/jmeterMetric";
	
	@Autowired
	private IJmeterMetricService jmeterMetricService;
	
	@RequiresPermissions("jmeter:jmeterMetric:view")
	@GetMapping()
	public String jmeterMetric()
	{
	    return prefix + "/jmeterMetric";
	}
	
	/**
	 * 查询jmeter测试计划调度列表
	 */
	@RequiresPermissions("jmeter:jmeterMetric:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(JmeterMetric jmeterMetric)
	{
		startPage();
        List<JmeterMetric> list = jmeterMetricService.selectJmeterMetricList(jmeterMetric);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出jmeter测试计划调度列表
	 */
	@RequiresPermissions("jmeter:jmeterMetric:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JmeterMetric jmeterMetric)
    {
    	List<JmeterMetric> list = jmeterMetricService.selectJmeterMetricList(jmeterMetric);
        ExcelUtil<JmeterMetric> util = new ExcelUtil<JmeterMetric>(JmeterMetric.class);
        return util.exportExcel(list, "jmeterMetric");
    }
	
	/**
	 * 新增jmeter测试计划调度
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存jmeter测试计划调度
	 */
	@RequiresPermissions("jmeter:jmeterMetric:add")
	@Log(title = "jmeter测试计划调度", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(JmeterMetric jmeterMetric)
	{		
		return toAjax(jmeterMetricService.insertJmeterMetric(jmeterMetric));
	}

	/**
	 * 修改jmeter测试计划调度
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		JmeterMetric jmeterMetric = jmeterMetricService.selectJmeterMetricById(id);
		mmap.put("jmeterMetric", jmeterMetric);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存jmeter测试计划调度
	 */
	@RequiresPermissions("jmeter:jmeterMetric:edit")
	@Log(title = "jmeter测试计划调度", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(JmeterMetric jmeterMetric)
	{		
		return toAjax(jmeterMetricService.updateJmeterMetric(jmeterMetric));
	}
	
	/**
	 * 删除jmeter测试计划调度
	 */
	@RequiresPermissions("jmeter:jmeterMetric:remove")
	@Log(title = "jmeter测试计划调度", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(jmeterMetricService.deleteJmeterMetricByIds(ids));
	}
	
}
